package com.java.module.cms.controller.admin;

import java.util.List;

import com.java.common.lang.annotation.Log;
import com.java.common.lang.domain.AjaxResult;
import com.java.common.lang.domain.page.TableDataInfo;
import com.java.common.lang.enums.BusinessTypeEnum;
import com.java.common.utils.WebKit;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.java.module.cms.domain.Data;
import com.java.module.cms.service.IDataService;
import com.java.common.utils.poi.ExcelUtil;

/**
 * 基础：基数数据Controller
 *
 * @author Administrator
 * @date 2021-04-19
 */
@RestController("AdminDataController")
@RequestMapping("/cms/data")
public class DataController {

    @Autowired
    private IDataService dataService;

    /**
     * 查询基础：基数数据列表
     */
    @PreAuthorize("@ss.hasPermi('cms:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(Data data) {
        WebKit.startPage();
        List<Data> list = dataService.selectDataList(data);
        return WebKit.getDataTable(list);
    }

    /**
     * 导出基础：基数数据列表
     */
    @PreAuthorize("@ss.hasPermi('cms:data:export')")
    @Log(title = "基础：基数数据", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Data data) {
        List<Data> list = dataService.selectDataList(data);
        ExcelUtil<Data> util = new ExcelUtil<Data>(Data.class);
        return util.exportExcel(list, "data");
    }

    /**
     * 获取基础：基数数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:data:query')")
    @GetMapping(value = "/{did}")
    public AjaxResult getInfo(@PathVariable("did") Long did) {
        return AjaxResult.success(dataService.selectDataById(did));
    }

    /**
     * 新增基础：基数数据
     */
    @PreAuthorize("@ss.hasPermi('cms:data:add')")
    @Log(title = "基础：基数数据", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Data data) {
        return WebKit.toAjax(dataService.insertData(data));
    }

    /**
     * 修改基础：基数数据
     */
    @PreAuthorize("@ss.hasPermi('cms:data:edit')")
    @Log(title = "基础：基数数据", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Data data) {
        return WebKit.toAjax(dataService.updateData(data));
    }

    /**
     * 删除基础：基数数据
     */
    @PreAuthorize("@ss.hasPermi('cms:data:remove')")
    @Log(title = "基础：基数数据", businessType = BusinessTypeEnum.DELETE)
    @DeleteMapping("/{dids}")
    public AjaxResult remove(@PathVariable Long[] dids) {
        return WebKit.toAjax(dataService.deleteDataByIds(dids));
    }

}